/*
 * Created on Feb 13, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.ba360.struts.action;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.ba360.portal.categories.MainCat;
import com.ba360.portal.categories.SubCatList;
import com.ba360.portal.categories.TestList;
import com.ba360.portal.common.PortalConstants;
import com.ba360.portal.database.DBConnectionImpl;
import com.ba360.portal.database.dbo.User;
import com.ba360.portal.util.Log;
import com.ba360.struts.form.DealsInfoBean;

/**
 * @author ROnat
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class DealsAction extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest req, HttpServletResponse res) throws Exception {
		// TODO Auto-generated method stub
		Log.init(this.getClass());

		String action = req.getParameter(PortalConstants.ACTION);

		HttpSession session = req.getSession();
		User user = (User) session.getAttribute("USER");
		String forward = "success";
		DealsInfoBean diBean = (DealsInfoBean) form;
		Connection conn = null;
		try {

			DBConnectionImpl dbConn = new DBConnectionImpl();
			conn = dbConn.getConnection();
			Statement stmt = conn.createStatement();
			Log.info("Deals Action: " + action);
			if (action == null) {
				ResultSet rs = conn.createStatement()
						.executeQuery("select category_id,name from dealscategories where par_category_id is null");
				MainCat[] mainCat = new MainCat[11];
				Log.init(this.getClass());
				Log.info("Fetch Size:" + rs.getFetchSize());
				int count = 0;
				List catList = new ArrayList();

				while (rs.next()) {
					Statement stmt1 = conn.createStatement();
					String mainCatName = rs.getString("name");
					Log.info("Deals Action: " + mainCatName);
					int mainCatId = rs.getInt("category_id");

					ResultSet rs1 = stmt1
							.executeQuery("select category_id,name from dealscategories where par_category_id="
									+ rs.getInt("category_id"));
					ArrayList subCat = new ArrayList();
					while (rs1.next()) {
						String subCatName = rs1.getString("name");
						int subCatId = rs1.getInt("category_id");

						SubCatList subCatList = new SubCatList(subCatName,
								subCatId);

						subCat.add(subCatList);
					}
					rs1.close();
					MainCat mainCatTemp = new MainCat(mainCatName, subCat);
					mainCatTemp.setMainCatId(mainCatId);
					mainCat[count] = mainCatTemp;
					count = count + 1;

					catList.add(mainCat);
				}
				rs.close();
				rs = stmt
						.executeQuery("select name,category_id from dealscategories");
				Hashtable categories = new Hashtable();
				Hashtable categoryIds = new Hashtable();
				while (rs.next()) {
					int mainCatId = rs.getInt("category_id");
					String catName = rs.getString("name");

					categories.put(mainCatId + "", catName);
				}
				rs.close();

				rs = stmt
						.executeQuery("select category_id,par_category_id from dealscategories");
				while (rs.next()) {
					int catId = rs.getInt("category_id");
					int parentCatId = rs.getInt("par_category_id");
					Log.info(catId + "  " + parentCatId);
					categoryIds.put(catId + "", parentCatId + "");
				}
				rs.close();

				session.setAttribute("DAPALLCATEGORY", categories);
				session.setAttribute("DAPCATIDS", categoryIds);
				TestList tl = new TestList(mainCat);
				session.setAttribute("DAPCATLIST", tl);//catList);

				stmt.close();

				forward = "dealscat";

			} else if (action != null) {
				if (action.equals("SearchAll")) {

					ResultSet rsBD = stmt
							.executeQuery("select * from businessdeals order by date_posted desc");
					ArrayList al = new ArrayList();
					while (rsBD.next()) {
						DealsInfoBean dib = new DealsInfoBean();
						dib.setTitle(rsBD.getString("title"));
						dib.setSubCat_id(rsBD.getString("cat_id"));
						String mainCatId = dLookUp(conn.createStatement(),
								"dealscategories", "par_category_id",
								"category_id=" + rsBD.getInt("cat_id"));
						dib.setCategory_id(mainCatId);
						String mainCatName = dLookUp(conn.createStatement(),
								"dealscategories", "name", "category_id="
										+ Integer.parseInt(mainCatId));
						dib.setMainCatName(mainCatName);
						String subCatName = dLookUp(conn.createStatement(),
								"dealscategories", "name", "category_id="
										+ rsBD.getInt("cat_id"));
						dib.setSubCatName(subCatName);
						dib.setDealsId(rsBD.getInt("deal_id"));
						dib.setBusinessId(rsBD.getInt("business_id"));
						dib.setDiscountPrice(rsBD.getString("discount_price"));
						dib.setDealDesc(rsBD.getString("deal_desc"));
						dib.setDatePosted(rsBD.getString("date_posted"));
						dib.setExpiry(rsBD.getString("expiry"));
						dib.setImg(rsBD.getString("img"));

						Log
								.info("select business_id,business_type,business_name,business_address,area_id,"
										+ "zip,email,website,business_phone,business_desc where business_id="
										+ rsBD.getInt("business_id"));
						Statement stmt1 = conn.createStatement();
						ResultSet rs = stmt1
								.executeQuery("select business_id,business_user_id,business_type,business_name,business_address,area_id,"
										+ "zip,email,website,business_phone,business_desc from businessinfo where business_id="
										+ rsBD.getInt("business_id"));
						while (rs.next()) {
							dib.setPlace_id(rs.getString("area_id"));
							String placeName = dLookUp(conn.createStatement(),
									"lookup_area", "name", "area_id="
											+ rs.getInt("area_id"));
							dib.setPlace(placeName);

							String locId = dLookUp(conn.createStatement(),
									"lookup_area", "par_category_id",
									"area_id=" + rs.getInt("area_id"));
							dib.setLoc_id(locId);
							String localName = dLookUp(conn.createStatement(),
									"lookup_area", "name", "area_id="
											+ Integer.parseInt(locId));
							dib.setLocation(localName);
							dib.setBusinessAddress(rs
									.getString("business_address"));
							dib.setBusinessDesc(rs.getString("business_desc"));
							dib.setBusinessId(rs.getInt("business_id"));
							dib.setBusinessName(rs.getString("business_name"));
							dib
									.setBusinessPhone(rs
											.getString("business_phone"));

							dib.setBusinessType(rs.getString("business_phone"));
							dib.setEmail(rs.getString("email"));
							dib.setZip(rs.getString("zip"));
							dib.setWebsite(rs.getString("website"));
							dib.setUserId(rs.getString("business_user_id"));

						}
						rs.close();
						stmt1.close();
						al.add(dib);
					}
					session.setAttribute("DealSearchResults", al);
					forward = "searchresult";
				}
				if (action.equals("SearchDeals")) {
					DealsInfoBean dib = new DealsInfoBean();
					String postingType = req.getParameter("PostingType");
					if (postingType != null) {
						if (!postingType.equals("99")){
							ArrayList al = new ArrayList();
						ResultSet rspt = conn.createStatement()
								.executeQuery("select category_id from dealscategories where par_category_id="
										+ Integer.parseInt(postingType));
						while (rspt.next()) {
							ResultSet rsBD = stmt
									.executeQuery("select * from businessdeals where cat_id="
											+ rspt.getInt("category_id") +" order by date_posted desc");
						
							while (rsBD.next()) {
								//ArrayList al = new ArrayList();
								dib = new DealsInfoBean();
								dib.setTitle(rsBD.getString("title"));
								dib.setSubCat_id(rsBD.getString("cat_id"));
								String mainCatId = dLookUp(conn
										.createStatement(), "dealscategories",
										"par_category_id", "category_id="
												+ rsBD.getInt("cat_id"));
								dib.setCategory_id(mainCatId);
								String mainCatName = dLookUp(conn
										.createStatement(), "dealscategories",
										"name", "category_id="
												+ Integer.parseInt(mainCatId));
								dib.setMainCatName(mainCatName);
								String subCatName = dLookUp(conn
										.createStatement(), "dealscategories",
										"name", "category_id="
												+ rsBD.getInt("cat_id"));
								dib.setSubCatName(subCatName);

								dib.setDealsId(rsBD.getInt("deal_id"));
								dib.setBusinessId(rsBD.getInt("business_id"));
								dib.setDiscountPrice(rsBD
										.getString("discount_price"));
								dib.setImg(rsBD.getString("img"));
								dib.setDealDesc(rsBD.getString("deal_desc"));
								dib
										.setDatePosted(rsBD
												.getString("date_posted"));
								dib.setExpiry(rsBD.getString("expiry"));
								Log
										.info("select business_id,business_type,business_name,business_address,area_id,"
												+ "zip,email,website,business_phone,business_desc where business_id="
												+ rsBD.getInt("business_id"));
								Statement stmt1 = conn.createStatement();
								ResultSet rs = stmt1
										.executeQuery("select business_id,business_user_id,business_type,business_name,business_address,area_id,"
												+ "zip,email,website,business_phone,business_desc from businessinfo where business_id="
												+ rsBD.getInt("business_id"));
								while (rs.next()) {
									dib.setPlace_id(rs.getString("area_id"));
									String placeName = dLookUp(conn
											.createStatement(), "lookup_area",
											"name", "area_id="
													+ rs.getInt("area_id"));
									dib.setPlace(placeName);

									String locId = dLookUp(conn
											.createStatement(), "lookup_area",
											"par_category_id", "area_id="
													+ rs.getInt("area_id"));
									dib.setLoc_id(locId);
									String localName = dLookUp(conn
											.createStatement(), "lookup_area",
											"name", "area_id="
													+ Integer.parseInt(locId));
									dib.setLocation(localName);
									dib.setBusinessAddress(rs
											.getString("business_address"));
									dib.setBusinessDesc(rs
											.getString("business_desc"));
									dib.setBusinessId(rs.getInt("business_id"));
									dib.setBusinessName(rs
											.getString("business_name"));
									dib.setBusinessPhone(rs
											.getString("business_phone"));

									dib.setBusinessType(rs
											.getString("business_phone"));
									dib.setEmail(rs.getString("email"));
									dib.setZip(rs.getString("zip"));
									dib.setWebsite(rs.getString("website"));
									dib.setUserId(rs
											.getString("business_user_id"));

								}
								al.add(dib);
							}
								
							
						}
						session.setAttribute("DealSearchResults", al);
						}
						} else {

						ResultSet rsBD = stmt
								.executeQuery("select * from businessdeals where cat_id="
										+ Integer.parseInt(req
												.getParameter("CatType"))+" order by date_posted desc");
						ArrayList al = new ArrayList();
						while (rsBD.next()) {
							dib = new DealsInfoBean();
							dib.setTitle(rsBD.getString("title"));
							dib.setSubCat_id(rsBD.getString("cat_id"));
							String mainCatId = dLookUp(conn.createStatement(),
									"dealscategories", "par_category_id",
									"category_id=" + rsBD.getInt("cat_id"));
							dib.setCategory_id(mainCatId);
							String mainCatName = dLookUp(
									conn.createStatement(), "dealscategories",
									"name", "category_id="
											+ Integer.parseInt(mainCatId));
							dib.setMainCatName(mainCatName);
							String subCatName = dLookUp(conn.createStatement(),
									"dealscategories", "name", "category_id="
											+ rsBD.getInt("cat_id"));
							dib.setSubCatName(subCatName);

							dib.setDealsId(rsBD.getInt("deal_id"));
							dib.setBusinessId(rsBD.getInt("business_id"));
							dib.setDiscountPrice(rsBD
									.getString("discount_price"));
							dib.setDealDesc(rsBD.getString("deal_desc"));
							dib.setDatePosted(rsBD.getString("date_posted"));
							dib.setImg(rsBD.getString("img"));
							dib.setExpiry(rsBD.getString("expiry"));
							Log
									.info("select business_id,business_type,business_name,business_address,area_id,"
											+ "zip,email,website,business_phone,business_desc where business_id="
											+ rsBD.getInt("business_id"));
							Statement stmt1 = conn.createStatement();
							ResultSet rs = stmt1
									.executeQuery("select business_id,business_user_id,business_type,business_name,business_address,area_id,"
											+ "zip,email,website,business_phone,business_desc from businessinfo where business_id="
											+ rsBD.getInt("business_id"));
							while (rs.next()) {
								dib.setPlace_id(rs.getString("area_id"));
								String placeName = dLookUp(conn
										.createStatement(), "lookup_area",
										"name", "area_id="
												+ rs.getInt("area_id"));
								dib.setPlace(placeName);

								String locId = dLookUp(conn.createStatement(),
										"lookup_area", "par_category_id",
										"area_id=" + rs.getInt("area_id"));
								dib.setLoc_id(locId);
								String localName = dLookUp(conn
										.createStatement(), "lookup_area",
										"name", "area_id="
												+ Integer.parseInt(locId));
								dib.setLocation(localName);
								dib.setBusinessAddress(rs
										.getString("business_address"));
								dib.setBusinessDesc(rs
										.getString("business_desc"));
								dib.setBusinessId(rs.getInt("business_id"));
								dib.setBusinessName(rs
										.getString("business_name"));
								dib.setBusinessPhone(rs
										.getString("business_phone"));

								dib.setBusinessType(rs
										.getString("business_phone"));
								dib.setEmail(rs.getString("email"));
								dib.setZip(rs.getString("zip"));
								dib.setWebsite(rs.getString("website"));
								dib.setUserId(rs.getString("business_user_id"));

							}
							al.add(dib);
						
						}
						
						//rs.close();
						//stmt1.close();
						session.setAttribute("DealSearchResults", al);
					}
					forward = "searchresult";
				}
					
				
				
				if (action.equals("SearchDealsL")) {
						diBean = new DealsInfoBean();
						String location = req.getParameter("Location");
						String catType = req.getParameter("CatType");
						
						if (location!=null)
						{
							ResultSet rs = stmt.executeQuery("select * from businessdeals order by date_posted desc");// where cat_id="+Integer.parseInt(catType));
							
							while (rs.next())
							{
								ArrayList a1 = new ArrayList();
								ResultSet rsN = conn.createStatement().executeQuery("select * from businessinfo where business_id="+rs.getInt("business_id"));
								while (rsN.next())
								{
									a1 = new ArrayList();
									diBean = new DealsInfoBean();
									System.out.println(" Area id "+rsN.getInt("area_id"));
									String loc =  dLookUp(conn.createStatement(),"lookup_area","par_category_id","area_id="+rsN.getInt("area_id"));
									
									System.out.println(loc+   "    "+location);
									if (loc.equals(location))
									{
										
										diBean.setTitle(rs.getString("title"));
										diBean.setSubCat_id(rs.getString("cat_id"));
										String mainCatId = dLookUp(conn
												.createStatement(), "dealscategories",
												"par_category_id", "category_id="
														+ rs.getInt("cat_id"));
										diBean.setCategory_id(mainCatId);
										String mainCatName = dLookUp(conn
												.createStatement(), "dealscategories",
												"name", "category_id="
														+ Integer.parseInt(mainCatId));
										diBean.setMainCatName(mainCatName);
										String subCatName = dLookUp(conn
												.createStatement(), "dealscategories",
												"name", "category_id="
														+ rs.getInt("cat_id"));
										diBean.setSubCatName(subCatName);

										diBean.setDealsId(rs.getInt("deal_id"));
										diBean.setBusinessId(rs.getInt("business_id"));
										diBean.setDiscountPrice(rs
												.getString("discount_price"));
										diBean.setDealDesc(rs.getString("deal_desc"));
										diBean.setImg(rs.getString("img"));
										diBean
												.setDatePosted(rs
														.getString("date_posted"));
										diBean.setExpiry(rs.getString("expiry"));
										diBean.setPlace_id(rsN.getString("area_id"));
										String placeName = dLookUp(conn
												.createStatement(), "lookup_area",
												"name", "area_id="
														+ rsN.getInt("area_id"));
										diBean.setPlace(placeName);

										/*String locId = dLookUp(conn
												.createStatement(), "lookup_area",
												"par_category_id", "area_id="
														+ rsN.getInt("area_id"));*/
										diBean.setLoc_id(location);
										String localName = dLookUp(conn
												.createStatement(), "lookup_area",
												"name", "area_id="
														+ Integer.parseInt(location));
										diBean.setLocation(localName);
										diBean.setBusinessAddress(rsN
												.getString("business_address"));
										diBean.setBusinessDesc(rsN
												.getString("business_desc"));
										diBean.setBusinessId(rsN.getInt("business_id"));
										diBean.setBusinessName(rsN
												.getString("business_name"));
										diBean.setBusinessPhone(rsN
												.getString("business_phone"));

										diBean.setBusinessType(rsN
												.getString("business_phone"));
										diBean.setEmail(rsN.getString("email"));
										diBean.setZip(rsN.getString("zip"));
										diBean.setWebsite(rsN.getString("website"));
										diBean.setUserId(rsN
												.getString("business_user_id"));
										
										
									}
									a1.add(diBean);
								}
								session.setAttribute("DealSearchResults",a1);
							}
						}else
						{
							
						}
						
						
						
					
					forward = "searchresult";
				}
				
				
				
				if (action.equals("PrintDeals")) {

					ResultSet rsBD = stmt
							.executeQuery("select * from businessdeals where deal_id="
									+ Integer.parseInt(req
											.getParameter("dealsId"))+" order by date_posted desc");
					ArrayList al = new ArrayList();
					while (rsBD.next()) {

						diBean.setTitle(rsBD.getString("title"));
						diBean.setSubCat_id(rsBD.getString("cat_id"));
						String mainCatId = dLookUp(conn.createStatement(),
								"dealscategories", "par_category_id",
								"category_id=" + rsBD.getInt("cat_id"));
						diBean.setCategory_id(mainCatId);
						String mainCatName = dLookUp(conn.createStatement(),
								"dealscategories", "name", "category_id="
										+ Integer.parseInt(mainCatId));
						diBean.setMainCatName(mainCatName);
						String subCatName = dLookUp(conn.createStatement(),
								"dealscategories", "name", "category_id="
										+ rsBD.getInt("cat_id"));
						diBean.setSubCatName(subCatName);

						diBean.setDealsId(rsBD.getInt("deal_id"));
						diBean.setBusinessId(rsBD.getInt("business_id"));
						diBean.setDiscountPrice(rsBD
								.getString("discount_price"));
						System.out.println(rsBD.getString("deal_desc"));
						diBean.setDealDesc(rsBD.getString("deal_desc"));
						diBean.setDatePosted(rsBD.getString("date_posted"));
						diBean.setImg(rsBD.getString("img"));
						diBean.setExpiry(rsBD.getString("expiry"));

						Log
								.info("select business_id,business_type,business_name,business_address,area_id,"
										+ "zip,email,website,business_phone,business_desc where business_id="
										+ rsBD.getInt("business_id"));
						Statement stmt1 = conn.createStatement();
						ResultSet rs = stmt1
								.executeQuery("select business_id,business_user_id,business_type,business_name,business_address,area_id,"
										+ "zip,email,website,business_phone,business_desc from businessinfo where business_id="
										+ rsBD.getInt("business_id"));
						while (rs.next()) {
							diBean.setPlace_id(rs.getString("area_id"));
							String placeName = dLookUp(conn.createStatement(),
									"lookup_area", "name", "area_id="
											+ rs.getInt("area_id"));
							diBean.setPlace(placeName);

							String locId = dLookUp(conn.createStatement(),
									"lookup_area", "par_category_id",
									"area_id=" + rs.getInt("area_id"));
							diBean.setLoc_id(locId);
							String localName = dLookUp(conn.createStatement(),
									"lookup_area", "name", "area_id="
											+ Integer.parseInt(locId));
							diBean.setLocation(localName);

							diBean.setBusinessAddress(rs
									.getString("business_address"));
							diBean.setBusinessDesc(rs
									.getString("business_desc"));
							diBean.setBusinessId(rs.getInt("business_id"));
							diBean.setBusinessName(rs
									.getString("business_name"));
							diBean.setBusinessPhone(rs
									.getString("business_phone"));

							diBean.setBusinessType(rs
									.getString("business_phone"));
							diBean.setEmail(rs.getString("email"));
							diBean.setZip(rs.getString("zip"));
							diBean.setWebsite(rs.getString("website"));
							diBean.setUserId(rs.getString("business_user_id"));

						}
						rs.close();
						stmt1.close();
						al.add(diBean);
					}
					session.setAttribute("DealSearchResults", al);
					System.out.println("PrintDeals From Deals Action");
					forward = "printdeal";
				}
				
				
				
				
				
				
				if (action.equals("DisplayDeals")) {

					ResultSet rsBD = stmt
							.executeQuery("select * from businessdeals where deal_id="
									+ Integer.parseInt(req
											.getParameter("dealsId"))+" order by date_posted desc");
					ArrayList al = new ArrayList();
					while (rsBD.next()) {

						diBean.setTitle(rsBD.getString("title"));
						diBean.setSubCat_id(rsBD.getString("cat_id"));
						String mainCatId = dLookUp(conn.createStatement(),
								"dealscategories", "par_category_id",
								"category_id=" + rsBD.getInt("cat_id"));
						diBean.setCategory_id(mainCatId);
						String mainCatName = dLookUp(conn.createStatement(),
								"dealscategories", "name", "category_id="
										+ Integer.parseInt(mainCatId));
						diBean.setMainCatName(mainCatName);
						String subCatName = dLookUp(conn.createStatement(),
								"dealscategories", "name", "category_id="
										+ rsBD.getInt("cat_id"));
						diBean.setSubCatName(subCatName);

						diBean.setDealsId(rsBD.getInt("deal_id"));
						diBean.setBusinessId(rsBD.getInt("business_id"));
						diBean.setDiscountPrice(rsBD
								.getString("discount_price"));
						diBean.setDealDesc(rsBD.getString("deal_desc"));
						diBean.setDatePosted(rsBD.getString("date_posted"));
						diBean.setExpiry(rsBD.getString("expiry"));
						diBean.setImg(rsBD.getString("img"));

						Log
								.info("select business_id,business_type,business_name,business_address,area_id,"
										+ "zip,email,website,business_phone,business_desc where business_id="
										+ rsBD.getInt("business_id"));
						Statement stmt1 = conn.createStatement();
						ResultSet rs = stmt1
								.executeQuery("select business_id,business_user_id,business_type,business_name,business_address,area_id,"
										+ "zip,email,website,business_phone,business_desc from businessinfo where business_id="
										+ rsBD.getInt("business_id"));
						while (rs.next()) {
							diBean.setPlace_id(rs.getString("area_id"));
							String placeName = dLookUp(conn.createStatement(),
									"lookup_area", "name", "area_id="
											+ rs.getInt("area_id"));
							diBean.setPlace(placeName);

							String locId = dLookUp(conn.createStatement(),
									"lookup_area", "par_category_id",
									"area_id=" + rs.getInt("area_id"));
							diBean.setLoc_id(locId);
							String localName = dLookUp(conn.createStatement(),
									"lookup_area", "name", "area_id="
											+ Integer.parseInt(locId));
							diBean.setLocation(localName);

							diBean.setBusinessAddress(rs
									.getString("business_address"));
							diBean.setBusinessDesc(rs
									.getString("business_desc"));
							diBean.setBusinessId(rs.getInt("business_id"));
							diBean.setBusinessName(rs
									.getString("business_name"));
							diBean.setBusinessPhone(rs
									.getString("business_phone"));

							diBean.setBusinessType(rs
									.getString("business_phone"));
							diBean.setEmail(rs.getString("email"));
							diBean.setZip(rs.getString("zip"));
							diBean.setWebsite(rs.getString("website"));
							diBean.setUserId(rs.getString("business_user_id"));

						}
						rs.close();
						stmt1.close();
						al.add(diBean);
					}
					session.setAttribute("DealSearchResults", al);
					forward = "viewdeal";
				}
				if (action.equals("DeleteDeals")) {
					String submit = req.getParameter("Submit");
					if (submit != null && submit.equals("Cancel")) {
						return mapping.findForward("myads");
					}
					stmt = conn.createStatement();
					stmt.execute("delete from businessdeals where deal_id="
							+ Integer.parseInt(req.getParameter("dealsId")));
					forward = "myads";
				}
			}
			} catch (Exception e) {
			throw e;
		} finally {
			conn.close();

		}
		//conn.close();
		return mapping.findForward(forward);
	}

	private String dLookUp(java.sql.Statement stat, String table, String fName,
			String where) {
		try {
			java.sql.ResultSet rs = openrs(stat, "SELECT " + fName + " FROM "
					+ table + " WHERE " + where);
			if (!rs.next()) {
				rs.close();
				return "";
			}
			String res = rs.getString(1);
			rs.close();
			return (res == null ? "" : res);
		} catch (Exception e) {
			return "";
		}
	}

	java.sql.ResultSet openrs(java.sql.Statement stat, String sql)
			throws java.sql.SQLException {
		java.sql.ResultSet rs = stat.executeQuery(sql);
		return (rs);
	}

}